﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>

<%@ Import Namespace="Buffalo.SMECommon.DAL" %>
<%@ Import Namespace="Buffalo.SMECommon.Enum" %>
<%@ Import Namespace="Buffalo.Web.Areas.SMECommon" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                hidIDEmployee.Value = ViewData["IDEmployee"];
            }
        }
    </script>

<script type="text/javascript">
    var commandHandler = function (cmd, record) {
        switch (cmd) {
            case "delete":
                Ext.Msg.confirm('Alert', 'Delete relationship?', function (btn) {
                    if (btn == "yes") {
                        dsFamilyRelationship.remove(record);
                        dsFamilyRelationship.save();
                    }
                });
                break;
        }
    };
    var addFamilyRelationshipHandler = function () {
        GridPanelFamilyRelationship.insertRecord(0, {IDEmployee: hidIDEmployee.getValue()});
        GridPanelFamilyRelationship.getView().focusRow(0);
        GridPanelFamilyRelationship.startEditing(0, 0);        
    };
</script>
<ext:GridPanel ID="GridPanelFamilyRelationship" runat="server" Header="false" Border="false" TrackMouseOver="true"
    AutoExpandColumn="FullName" StoreID="dsFamilyRelationship" Height="400" Width = "600">
    <ColumnModel ID="ColumnModel1" runat="server">
        <Columns>
            <ext:CommandColumn Width="25" Hideable="false">
                <Commands>
                    <ext:GridCommand CommandName="delete" Icon="Cross">
                        <ToolTip Text="Delete" />
                    </ext:GridCommand>
                </Commands>
                <PrepareToolbar Handler="toolbar.setVisible(!record.newRecord);" />
            </ext:CommandColumn>
            <ext:Column ColumnID="FullName" DataIndex="FullName" Header="FullName" Width="200">
                <Editor>
                    <ext:TextField ID="TextField1" runat="server" AllowBlank="false" />
                </Editor>
            </ext:Column>
            <ext:DateColumn ColumnID="DOB" DataIndex="DOB" Header="DOB" Format="dd/MM/yyyy" >
                <Editor>
                    <ext:DateField ID="DateField2" runat="server" AllowBlank="true" />
                </Editor>
            </ext:DateColumn>
            <ext:Column ColumnID="Relationship" DataIndex="Relationship" Header="Relationship" Width="150">
                <Editor>
                    <ext:TextField ID="TextField2" runat="server" AllowBlank="true" />
                </Editor>
            </ext:Column>
        </Columns>
    </ColumnModel>
        <TopBar>
        <ext:Toolbar ID="mainToolbar" runat="server">
            <Items>
                <ext:Button ID="btnSaveFamily" runat="server" Text="Save" Icon="Disk">
                    <Listeners>
                        <Click Handler="#{dsFamilyRelationship}.save();" />
                    </Listeners>
                </ext:Button>
                <ext:Button ID="btnAdd" runat="server" Text="Add" Icon="Add">
                    <Listeners>
                        <Click Handler="addFamilyRelationshipHandler();" />
                    </Listeners>
                </ext:Button>
            </Items>
        </ext:Toolbar>
    </TopBar>
    <SelectionModel>
        <ext:RowSelectionModel ID="RowSelectionModel2" runat="server" />
    </SelectionModel>
    <BottomBar>
        <ext:PagingToolbar ID="PagingToolbar2" runat="server" PageSize="15" />
    </BottomBar>
    <Listeners>
        <Command Fn="commandHandler" />
        <BeforeEdit Handler="return !(e.field=='ID' && !e.record.newRecord);" />
    </Listeners>
    <LoadMask ShowMask="true" />
    <SaveMask ShowMask="true" />
</ext:GridPanel>
<ext:Hidden ID="hidIDEmployee" runat="server"></ext:Hidden>
